/**
 * @file index.js
 * @author swan
 */
const app = getApp()

Page({
    data: {
        indicatorDots: true,
        autoplay: true,
        interval: 5000,
        duration: 1300,
        Height: "",
        IndexBannerUrl: [],
        array: ['无锡', '锡山', '惠山', '滨湖', '梁溪', '新吴', '江阴', '宜兴'],
        index: 0,//默认显示位置
        staticImageurl: app.globalData.staticImageurl,
    },
    bindPickerChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value
        })
    },
    imgHeight: function (e) {
        var winWid = swan.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
        var imgh = e.detail.height; //图片高度
        var imgw = e.detail.width; //图片宽度
        var swiperH = winWid * imgh / imgw + "px"
        this.setData({
            Height: swiperH //设置高度
        })
    },
    bindViewTap: function (event) {
        var cid = event.currentTarget.dataset.cid;
        console.log(cid)
        if (cid == 5) {
            swan.switchTab({
                url: event.currentTarget.dataset.link // 页面跳转地址
            })
        } else {
            if (event.currentTarget.dataset.link) {
                swan.navigateTo({
                    url: event.currentTarget.dataset.link // 页面跳转地址
                })
            }
        }

    },
    tiaozhuan(e) {
        console.log(e)
        swan.setStorageSync('newdetail', e.currentTarget.dataset.item);
        swan.navigateTo({
            url: '../newsDetail/newsDetail'
        });
    },
    onLoad() {
        // 监听页面加载的生命周期函数
        //banner
        let that = this;
        let cates = {};
        let sort = [];
        getApp().rq('/Index/getXcxconfig').then(res => {
            getApp().globalData.config = res.data;
            res.data.forEach(function (item) {
                if (item.del == 0) {
                    sort.push(item.key)
                }
            })
            res.data.forEach(function (item) {
                cates[item.key] = item;
            });
            that.setData({
                sort,
                cates,
                imageurl: getApp().globalData.imageurl
            });
            that.init();
        })
        getApp().rq('/Index/getBanner').then(res => {
            this.setData({
                imgurl: getApp().globalData.imageurl,
                banner: res.data
            });
            swan.setStorageSync("banner", res.data);
        });
        // 
    },
    gotopros(e) {
        let id = e.currentTarget.dataset.id;
        swan.setStorageSync('iiid', id);
        console.log(id)
        swan.switchTab({
            url: '../productList/productList?id=' + id
        });
    },
    getMoreGoods(e) {
        let id = e.currentTarget.dataset.id;
        swan.navigateTo({
            url: '../product/product?id=' + id
        });
    },
    prodetail(e) {
        var info = e.currentTarget.dataset.info;
        swan.setStorageSync('prodetail', info);
        swan.navigateTo({
            url: '../productDetail/productDetail'
        });
    },
    init() {
        let that = this
        let cates = this.data.cates;
        for (let i in cates) {
            if (cates[i].del == 0) {
                getApp().rq('/Index/getList', {
                    typeid: cates[i].alis,
                    limit: 4,
                    sort: cates[i].sortname
                }).then(res => {
                    cates[i].data = res.data;
                    that.setData({
                        cates
                    })
                    console.log(cates)
                })
            }
        }
    },
    search() {
        swan.navigateTo({
            url: '../search/search'
        });
    },
    news: function (e) {
        swan.switchTab({
            url: '../news/news'
        })
    },
    case: function (e) {
        swan.switchTab({
            url: '../case/case'
        })
    },
    product: function (e) {
        swan.navigateTo({
            url: '../product/product'
        })
    },
    message: function (e) {
        swan.navigateTo({
            url: '../message/message'
        });
    },
    onShow() {
        swan.setPageInfo({
            title: '百拓教育',
            keywords: '学历提升，职业技能',
            description: '百拓教育等你来',
            image: 'https://jiaoyu.jsbestop.com/uploads/abc1/20190713/5d2941283a245.jpg',
            articleTitle: '',
            releaseDate: '',
            visit: {
                pv: '1000',
                uv: '100',
                sessionDuration: '130'
            },
            likes: '75',
            comments: '13',
            collects: '23',
            shares: '8',
            followers: '35',
            success: function () {
                console.log('setPageInfo success');
            },
            fail: function (err) {
                console.log('setPageInfo fail', err);
            }
        })
    }

})
